import subprocess, os
from flask import Flask
app = Flask(__name__)

SCRIPTS_ROOT = '/home/gjh/pytools' 

@app.route('/run/<script_name>')
def run_script(script_name):
    fp = os.path.join(SCRIPTS_ROOT, script_name)
    try:
        output = subprocess.check_output(['python', fp])
    except subprocess.CalledProcessError as call:
        output = call.output # if exit code was non-zero
    return output.decode('utf-8') # or your system encoding

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5000)

